<?php
include("fonction.php");
include("user.php");
session_start();
if (isset($_GET['deconnexion']) && $_GET['deconnexion']){
	$_SESSION['active'] = 0;
	$_SESSION['user'] = false;
}
if (isset($_SESSION['active']) and $_SESSION['active'] == 1)
	{
		$user = &$_SESSION['user'];
	}
	else
	{
		$user = new user();
		$_SESSION['user'] = $user;
		$_SESSION['active'] = 1;
	}
if (isset($_POST['hidden']) and $_POST['hidden']=="user_login"){
		if (! $user->check_password($_POST['f_login'],$_POST['f_password'])){
			header("Location: error.php?err=logfail");
		}
	}
if($user->film || $user->music){
	if(isset($_GET['download'])){
			download($_GET['download']);
			}
}
function contenu($user){
		if($_GET['page']=="admin" and $user->admin ==1){
			if($_GET['refresh']){
				refresh();
				echo '<script>alert("refresh fait");</script>';
			}
			if($_POST['hidden']== "add_user")
			{
				add_user();
			}
			if(isset($_GET['user']) && $_GET['delete']== "1"){
				delete_user();
			}
			if($_POST['hidden']== "add_news")
			{
				add_news($_POST['i_titre'],$_POST['i_contenu']);
			}
			if(isset($_GET['news']) && $_GET['delete']== "1"){
				delete_news();
			}
			div_admin();
		}elseif($_GET['page']=="film" && $user->film){
			div_film();
		}elseif($_GET['page']=="music" && $user->music){
			div_music();
		}elseif($_GET['page']=="search" && ($user->music || $user->film)){
			if($user->music && $user->film){
				div_search("all",htmlentities(stripslashes($_POST['search'])));
			}elseif($user->music){
				div_search("music",htmlentities(stripslashes($_POST['search'])));
			}elseif($user->film){
				div_search("film",htmlentities(stripslashes($_POST['search'])));
			}else{
				div_search("search","");
			}
		
			
		}else{
			div_accueil();
		}
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<title>MG Server : Zone libre !</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" href="style.css" type="text/css" />
	</head>
	
	<body>
		<div id="global">								
			<div id="baniere">
			</div>
			<div id="menu">
				<h1>Site</h1>
				<ul>
					<li><a href="?page=accueil">Accueil</a></li>
					<li><a href="?page=film">Film</a></li>
					<li><a href="?page=music">Musique</a></li>
					<li><a href="?page=admin">Administration</a></li>
					<li><a href="?page=search">Recherche</a></li>
				</ul>
				<h1> Externe</h1>
				<ul>
					<li><a href="http://search.podzone.org/" target="_blank">Search film</a></li>
					<li><a href="http://baloo.dyndns.org/" target="_blank">Baloo</a></li>
					<li><a href="http://bandoine.hd.free.fr/" target="_blank">Bandoine</a></li>
					<li><a href="http://hikabox.com/" target="_blank">Hikaru</a></li>
					<li><a href="http://bodji.net" target="_blank">Bodji</a></li>
				</ul>
				<h1>Login</h1>
				<ul>
				<?php 
					if($user->login == "anonyme"){
						echo "<form action='index.php' method='post' >";
						echo "<li>Login : <input type = 'text' name='f_login' /></li>";
						echo "<li>Password: <input type='password' name='f_password' /></li>";
						echo "<li><input type='hidden' name='hidden' value='user_login' /><input type='submit' value='Connect' /></li>";
						echo "</form>";
					}else{
						echo "<li>Bienvenue <span id='login'>".$user->login."</span></li>";
						echo "<li><a href='?deconnexion=1'>D&eacute;connexion</a></li>";
					}
					
					?>
				</ul>
			</div>
			<div id="contenu">
				<?php Contenu($user);?> 
			</div>
			<div id="footer">
			<p>&copy;2008 | Tous droits r&eacute;serv&eacute;s | MetalGun (Merci Bewiwi)| BMBTeam</p>
			</div>
		</div>
	</body>
</html>
<?php
?>